package 湖北大学;

import bean.ExBean;
import bean.HbU;
import com.alibaba.excel.EasyExcel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;

public class HNU extends Exception {
    public static void main(String[] args) throws IOException {
        ArrayList<HbU> hnus = new ArrayList<>();
        String Url = "http://eeit.hnu.edu.cn/szdw/szll.htm";
        Document document = Jsoup.connect(Url).get();

        Elements teacherList2 = document.getElementsByClass("teacher_list2");
        Elements li = teacherList2.get(0).getElementsByTag("ul");
        Elements li1 = li.get(1).getElementsByTag("li");
        Elements li2 = li.get(2).getElementsByTag("li");
        HbU hbU;
        HbU hbU2;
        for (Element element : li1) {
            hbU = new HbU();
            String href = element.getElementsByTag("a").attr("href");
            String delete = HNU.Delete(href, "../");
            String Url2 = "http://eeit.hnu.edu.cn/" + delete;
            //教授姓名
            String name = element.text();
//            System.out.println("1姓名" + name + Url2);
            hbU.setName(name);
            hbU.setXX(Url2);
            hnus.add(hbU);
        }
        for (Element element : li2) {
            hbU2 =new HbU();
            String href = element.getElementsByTag("a").attr("href");
            String delete = HNU.Delete(href, "../");
            String Url2 = "http://eeit.hnu.edu.cn/" + delete;
            //教授姓名
            String name = element.text();
//            System.out.println("2姓名" + name + Url2);
            hbU2.setName(name);
            hbU2.setXX(Url2);
            hnus.add(hbU2);
        }
        EasyExcel.write("src/hubei.xlsx", HbU.class).sheet("hubei").doWrite(hnus);
    }

    public static String Delete(String elementText, String chElemData) {
        String replace = elementText.replace(chElemData, "");
        return replace;
    }

}

